<template>
  <div>
    <input
      type="text"
      v-model="inputVal"
      placeholder="请输入你的任务名称，按回车键确认"
      @keydown.enter="add"
    />
  </div>
</template>
<script>
export default {
  data() {
    return {
      inputVal: "",
    };
  },
  methods: {
    add() {
      if (!this.inputVal) {
        alert("内容不能为空");
      } else {
        this.$store.commit("addList", this.inputVal);
        this.inputVal = "";
      }
    },
  },
};
</script>